package inits

import (
	"fmt"
	"takeout-grpc/basic/config"

	"github.com/nacos-group/nacos-sdk-go/clients"
	"github.com/nacos-group/nacos-sdk-go/common/constant"
	"github.com/nacos-group/nacos-sdk-go/vo"
)

func InitNacos() {
	data := config.Config.Nacos
	clientConfig := constant.ClientConfig{
		NamespaceId:         data.PublicId, //we can create multiple clients with different namespaceId to support multiple namespace.When namespace is public, fill in the blank string here.
		TimeoutMs:           5000,
		NotLoadCacheAtStart: false,
		LogDir:              "/tmp/nacos/log",
		CacheDir:            "/tmp/nacos/cache",
		LogLevel:            "debug",
	}
	serverConfigs := []constant.ServerConfig{
		{
			IpAddr:      data.Host,
			ContextPath: "/nacos",
			Port:        uint64(data.Port),
			Scheme:      "http",
		},
	}
	configClient, err := clients.NewConfigClient(
		vo.NacosClientParam{
			ClientConfig:  &clientConfig,
			ServerConfigs: serverConfigs,
		},
	)
	if err != nil {
		panic("创建nacos配置失败")
	}
	content, err := configClient.GetConfig(vo.ConfigParam{
		DataId: data.DataId,
		Group:  data.Group})
	fmt.Println("nacos 启动成功",
		content)

}
